home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / 3D Buttons CDEF 1.0b6 / Source / 3D Buttons CDEF source / (3D CDEF++.68k.π) / LCDEFCheckboxOrRadioButton.cp < prev    next >
Text File  |  1994-12-28  |  4KB  |  133 lines

  1. /*
  2.     Public domain by Zig Zichterman.
  3. */
  4. /*
  5.     LCDEFCheckboxOrRadioButton
  6.     
  7.     Base class for checkboxes and radio buttons
  8.     
  9.     12/28/94    zz    h    initial write
  10. */
  11. #pragma once
  12.  
  13. #include "LCDEFCheckboxOrRadioButton.h"
  14.  
  15. #include "RgnHandleT.h"
  16. #include <Script.h>
  17. #include <TextEdit.h>
  18.  
  19. /**************************************************************************
  20.     SetBGColorToErase()                                [protected, virtual]
  21.                                                     [complete override ]
  22.     Use the background color, or white
  23. **************************************************************************/
  24. void
  25. LCDEFCheckboxOrRadioButton::SetBGColorToErase(
  26.     Is3DFlagT            inIs3D,
  27.     IsEnabledFlagT        /*inIsEnabled*/,
  28.     IsHighlightedFlagT    /*inIsHighlighted*/) const
  29. {
  30.     // if we have enough colors
  31.     if (inIs3D) {
  32.         // use background color
  33.         ::RGBBackColor(&mBackgroundColor);
  34.     } else {
  35.         // use white
  36.         ::BackColor(whiteColor);
  37.     }
  38. }
  39.  
  40. /**************************************************************************
  41.     Erase()                                            [protected, virtual]
  42.                                                     [complete override ]
  43.     
  44.     Just erase the entire rect. This would be really flicker-prone, but
  45.     we have offscreen GWorlds to take away this ugliness. People who
  46.     still run machines incapable of offscreen GWorlds will just have
  47.     to live with the flicker, or buy a new machine...
  48. **************************************************************************/
  49. void 
  50. LCDEFCheckboxOrRadioButton::Erase(void) const
  51. {
  52.     RectT    controlRect;
  53.     GetControlRect(controlRect);
  54.     ::EraseRect(&controlRect);
  55. }
  56.  
  57. /**************************************************************************
  58.     CalcPartRects()                                    [protected, virtual]
  59.                                                     [complete override ]
  60.  
  61.     Where should the checkbox/radio button go, and where should the 
  62.     title go? Fills in mRadioCheckRect and mTitleRect.
  63. **************************************************************************/
  64. void
  65. LCDEFCheckboxOrRadioButton::CalcPartRects(void)
  66. {
  67.     // get the control rect
  68.     RectT    controlRect;
  69.     GetControlRect(controlRect);
  70.     
  71.     // ———— vertical coords ————
  72.     // get the vertical center of the control
  73.     const short    CenterV    = (controlRect.top + controlRect.bottom)/2;
  74.     
  75.     // checkbox is v-centered, 12-px tall
  76.     mRadioCheckRect.top 
  77.         = CenterV - (CheckboxOrRadioButtonSizePixels/2);
  78.     mRadioCheckRect.bottom
  79.         = mRadioCheckRect.top + CheckboxOrRadioButtonSizePixels;
  80.  
  81.     // textbox fills from top to bottom, DrawTitle() takes
  82.     // care of vertically centering the actual text
  83.     mTitleRect.top                = controlRect.top;
  84.     mTitleRect.bottom            = controlRect.bottom;
  85.  
  86.     // ———— horizontal coords ————
  87.     // is the Macintosh's current system script predominantly left-to-right?
  88.     // (such as English)
  89.     const Boolean        IsLeftToRight    = (::GetSysJust() == 0);
  90.     
  91.     // checkbox is left- or right-aligned, offset by a couple pix
  92.     if (IsLeftToRight) {
  93.         mRadioCheckRect.left    = controlRect.left + 2;
  94.         mRadioCheckRect.right    = mRadioCheckRect.left
  95.                                     + CheckboxOrRadioButtonSizePixels;
  96.     } else {
  97.         mRadioCheckRect.right    = controlRect.right - 2;
  98.         mRadioCheckRect.left    = mRadioCheckRect.right
  99.                                     - CheckboxOrRadioButtonSizePixels;
  100.     }
  101.     
  102.     // textbox is next to the checkbox
  103.     if (IsLeftToRight) {
  104.         mTitleRect.left        = mRadioCheckRect.right + 3;
  105.         mTitleRect.right    = controlRect.right;
  106.     } else {
  107.         mTitleRect.right    = mRadioCheckRect.left - 3;
  108.         mTitleRect.left        = controlRect.left;
  109.     }
  110. }
  111.         
  112. /**************************************************************************
  113.     DrawTitle()                                        [protected, virtual]
  114.     
  115.     Draw the title, using the system default alignment, centered
  116.     vertically in the title rect. 
  117. **************************************************************************/
  118. void 
  119. LCDEFCheckboxOrRadioButton::DrawTitle(
  120.     Is3DFlagT            /*inIs3D*/,
  121.     IsHighlightedFlagT    /*inIsHighlighted*/,
  122.     Rect &                outTitleRect) const
  123. {
  124.     // get the title
  125.     const StringPtr    TitleStr    = GetControlTitle();
  126.     
  127.     // draw it
  128.     StringBox(TitleStr,mTitleRect,teFlushDefault);
  129.  
  130.     // return the box we used
  131.     outTitleRect = mTitleRect;
  132. }
  133.